package com.fhz.big

import android.annotation.SuppressLint
import android.app.Activity
import android.app.Application
import android.content.pm.ApplicationInfo
import android.os.Bundle
import androidx.core.content.edit
import com.alibaba.android.arouter.launcher.ARouter
import com.fhz.common.config.ModuleLifecycleConfig
import com.fhz.common.manage.MyActivityManage
import dagger.hilt.android.HiltAndroidApp

/**
 * 时间:2023/3/27
 * @author Mr.Feng
 * 简述: 总启动项目,在这个里面定义可以启动的moudel
 */
@HiltAndroidApp
class MyApp :Application() {

    override fun onCreate() {
        super.onCreate()
        //p版本以后,不能直接通过反射来使用
//        ModuleLifecycleConfig.initModule(this)


//        val sharedPreferences = getSharedPreferences("xiaomign", MODE_PRIVATE)
//        val edit = sharedPreferences.edit()
//        edit.putInt("age",1)
//        edit.apply()
//
//        getSharedPreferences("data", MODE_PRIVATE).edit {
//            putString("name", "Tom")
//            putInt("age", 28)
//            putBoolean("married", false)
//        }
//
//
//
//        getSharedPreferences("xiaomign", MODE_PRIVATE).abc {
//            putInt("age",1)
//            putBoolean("age",true)
//        }



        ARouter.openLog() // 开启日志
        ARouter.openDebug() // 使用InstantRun的时候，需要打开该开关，上线之后关闭，否则有安全风险
        ARouter.printStackTrace() // 打印日志的时候打印线程堆栈
        ARouter.init(this)

        //注册所有界面的回调
        registerActivityLifecycleCallbacks(object:ActivityLifecycleCallbacks{
            override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
                MyActivityManage.addActivity(activity)
//                println(MyActivityManage.stack.size)
            }

            override fun onActivityStarted(activity: Activity) {
            }

            override fun onActivityResumed(activity: Activity) {
            }

            override fun onActivityPaused(activity: Activity) {
            }

            override fun onActivityStopped(activity: Activity) {
            }

            override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {
            }

            override fun onActivityDestroyed(activity: Activity) {
                MyActivityManage.removeActivity(activity)
//                println(MyActivityManage.stack.size)
//
            }
        })
    }




}